/*
 * Created by JFormDesigner on Sun Jun 26 15:49:10 CST 2022
 */

package com.keshe.jsp;

import com.keshe.service.RoomContorller;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author 1
 */
public class UpdateRoom extends JFrame {
    public UpdateRoom() {
        initComponents();

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");
        menuBar1 = new JMenuBar();
        menu1 = new JMenu();
        menuItem1 = new JMenuItem();
        menuItem2 = new JMenuItem();
        menuItem3 = new JMenuItem();
        panel1 = new JPanel();
        label8 = new JLabel();
        textField4 = new JTextField();
        label9 = new JLabel();
        textField5 = new JTextField();
        label10 = new JLabel();
        comboBox2 = new JComboBox<>();
        label11 = new JLabel();
        textField6 = new JTextField();
        label12 = new JLabel();
        radioButton2 = new JRadioButton();
        radioButton3 = new JRadioButton();
        label13 = new JLabel();
        comboBox3 = new JComboBox<>();
        label14 = new JLabel();
        textField7 = new JTextField();
        label1 = new JLabel();
        textField2 = new JTextField();
        radioButton5 = new JRadioButton();
        radioButton6 = new JRadioButton();
        textField1 = new JTextField();
        button3 = new JButton();
        action1 = new update();
        action2 = new Return();
        action3 = new select();
        action4 = new deleteRoom();

        //======== this ========
        setIconImage(new ImageIcon(getClass().getResource("/images/\u9152\u5e97 (1).png")).getImage());
        setTitle("\u4fee\u6539\u5ba2\u623f\u4fe1\u606f");
        Container contentPane = getContentPane();

        //======== menuBar1 ========
        {

            //======== menu1 ========
            {
                menu1.setText(bundle.getString("menu1.text"));

                //---- menuItem1 ----
                menuItem1.setAction(action1);
                menuItem1.setText(bundle.getString("menuItem1.text"));
                menu1.add(menuItem1);

                //---- menuItem2 ----
                menuItem2.setAction(action4);
                menu1.add(menuItem2);

                //---- menuItem3 ----
                menuItem3.setText(bundle.getString("menuItem3.text"));
                menuItem3.setAction(action2);
                menu1.add(menuItem3);
            }
            menuBar1.add(menu1);
        }
        setJMenuBar(menuBar1);

        //======== panel1 ========
        {

            //---- label8 ----
            label8.setText(bundle.getString("label8.text_2"));
            label8.setIcon(new ImageIcon(getClass().getResource("/images/\u7f16\u53f7.png")));

            //---- textField4 ----
            textField4.setEditable(false);

            //---- label9 ----
            label9.setText(bundle.getString("label9.text_2"));
            label9.setIcon(new ImageIcon(getClass().getResource("/images/\u5165\u5e93\u7c7b\u578b.png")));

            //---- label10 ----
            label10.setText(bundle.getString("label10.text_2"));
            label10.setIcon(new ImageIcon(getClass().getResource("/images/\u4f4d\u7f6e.png")));

            //---- comboBox2 ----
            comboBox2.setModel(new DefaultComboBoxModel<>(new String[] {
                "--\u8bf7\u9009\u62e9--",
                "1\u697c",
                "2\u697c",
                "3\u697c"
            }));

            //---- label11 ----
            label11.setText(bundle.getString("label11.text_2"));
            label11.setIcon(new ImageIcon(getClass().getResource("/images/\u4ef7\u683c.png")));

            //---- label12 ----
            label12.setText(bundle.getString("label12.text_2"));
            label12.setIcon(new ImageIcon(getClass().getResource("/images/\u7b49\u5f85sap\u7a7a\u95f2.png")));

            //---- radioButton2 ----
            radioButton2.setText(bundle.getString("radioButton2.text_2"));
            radioButton2.setEnabled(false);

            //---- radioButton3 ----
            radioButton3.setText(bundle.getString("radioButton3.text_2"));
            radioButton3.setEnabled(false);

            //---- label13 ----
            label13.setText(bundle.getString("label13.text_2"));
            label13.setIcon(new ImageIcon(getClass().getResource("/images/\u6e05\u6d01.png")));

            //---- comboBox3 ----
            comboBox3.setModel(new DefaultComboBoxModel<>(new String[] {
                "--\u8bf7\u9009\u62e9--",
                "\u5df2\u6e05\u6d01",
                "\u672a\u6e05\u6d01"
            }));

            //---- label14 ----
            label14.setText(bundle.getString("label14.text_2"));
            label14.setIcon(new ImageIcon(getClass().getResource("/images/\u63cf\u8ff0.png")));

            //---- label1 ----
            label1.setText("住房面积");
            label1.setIcon(new ImageIcon(getClass().getResource("/images/\u4eba\u5747\u4f4f\u623f\u9762\u79ef.png")));

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(89, 89, 89)
                        .addGroup(panel1Layout.createParallelGroup()
                            .addComponent(textField7, GroupLayout.DEFAULT_SIZE, 458, Short.MAX_VALUE)
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGroup(panel1Layout.createParallelGroup()
                                    .addGroup(panel1Layout.createSequentialGroup()
                                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                            .addGroup(panel1Layout.createSequentialGroup()
                                                .addGroup(panel1Layout.createParallelGroup()
                                                    .addComponent(label8)
                                                    .addComponent(label10))
                                                .addGap(18, 18, 18)
                                                .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                    .addComponent(textField4, GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                                                    .addComponent(comboBox2, GroupLayout.DEFAULT_SIZE, 1, Short.MAX_VALUE)))
                                            .addGroup(panel1Layout.createSequentialGroup()
                                                .addGroup(panel1Layout.createParallelGroup()
                                                    .addComponent(label12)
                                                    .addComponent(label1))
                                                .addGap(18, 18, 18)
                                                .addGroup(panel1Layout.createParallelGroup()
                                                    .addGroup(panel1Layout.createSequentialGroup()
                                                        .addComponent(radioButton2)
                                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                                                        .addComponent(radioButton3))
                                                    .addComponent(textField2, GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))))
                                        .addGap(75, 75, 75)
                                        .addGroup(panel1Layout.createParallelGroup()
                                            .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                .addGroup(panel1Layout.createSequentialGroup()
                                                    .addComponent(label11)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(textField6))
                                                .addGroup(panel1Layout.createSequentialGroup()
                                                    .addComponent(label9)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(textField5, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE)))
                                            .addGroup(panel1Layout.createSequentialGroup()
                                                .addComponent(label13)
                                                .addGap(18, 18, 18)
                                                .addComponent(comboBox3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
                                    .addComponent(label14))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap(54, Short.MAX_VALUE))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label8)
                            .addComponent(textField4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(label9)
                            .addComponent(textField5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label10)
                            .addComponent(comboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(label11)
                            .addComponent(textField6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label12)
                            .addComponent(radioButton3)
                            .addComponent(radioButton2)
                            .addComponent(label13)
                            .addComponent(comboBox3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label1)
                            .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(label14)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textField7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32))
            );
        }

        //---- radioButton5 ----
        radioButton5.setText(bundle.getString("radioButton5.text"));

        //---- radioButton6 ----
        radioButton6.setText(bundle.getString("radioButton6.text"));

        //---- button3 ----
        button3.setAction(action3);
        button3.setText("\u641c\u7d22");
        button3.setIcon(new ImageIcon(getClass().getResource("/images/\u641c\u7d22.png")));

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(96, 96, 96)
                    .addComponent(radioButton5)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(radioButton6)
                    .addGap(31, 31, 31)
                    .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
                    .addGap(38, 38, 38)
                    .addComponent(button3)
                    .addContainerGap(52, Short.MAX_VALUE))
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addGap(41, 41, 41)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(radioButton5)
                        .addComponent(radioButton6)
                        .addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(button3))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(21, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JMenuBar menuBar1;
    private JMenu menu1;
    private JMenuItem menuItem1;
    private JMenuItem menuItem2;
    private JMenuItem menuItem3;
    private JPanel panel1;
    private JLabel label8;
    private JTextField textField4;
    private JLabel label9;
    private JTextField textField5;
    private JLabel label10;
    private JComboBox<String> comboBox2;
    private JLabel label11;
    private JTextField textField6;
    private JLabel label12;
    private JRadioButton radioButton2;
    private JRadioButton radioButton3;
    private JLabel label13;
    private JComboBox<String> comboBox3;
    private JLabel label14;
    private JTextField textField7;
    private JLabel label1;
    private JTextField textField2;
    private JRadioButton radioButton5;
    private JRadioButton radioButton6;
    private JTextField textField1;
    private JButton button3;
    private update action1;
    private Return action2;
    private select action3;
    private deleteRoom action4;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    private class update extends AbstractAction {
        private update() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action1.Name_12"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            RoomContorller rc = new RoomContorller();
            int flag = rc.updateRoom(textField4.getText(), textField5.getText(), String.valueOf(comboBox2.getSelectedItem()), Integer.parseInt(textField6.getText()), textField2.getText(),radioButton2.getText(), String.valueOf(comboBox3.getSelectedItem()), textField7.getText());
            if (flag == 1) {
                dispose();
                JOptionPane.showMessageDialog(null, "修改成功！");
                new Index().setVisible(true);
            }
            if (flag == 0) {
                JOptionPane.showMessageDialog(null, "请完善数据再提交！");
            }
            if (flag == -1) {
                JOptionPane.showMessageDialog(null, "修改失败，请重试！");
            }
        }
    }

    private class Return extends AbstractAction {
        private Return() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action2.Name_6"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            dispose();
            new Index().setVisible(true);
        }
    }

    private class select extends AbstractAction {
        private select() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action3.Name_3"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            if (radioButton5.isSelected() == true && radioButton6.isSelected() == true) {
                JOptionPane.showMessageDialog(null, "只能选择一种查询方式哦！");
            } else if (radioButton5.isSelected() == false && radioButton6.isSelected() == false) {
                JOptionPane.showMessageDialog(null, "至少选择一种查询方式哦！");
            } else if (radioButton5.isSelected() == true) {
                RoomContorller rc = new RoomContorller();
                if (rc.selectId(textField1.getText()).length == 0) {
                    JOptionPane.showMessageDialog(null, "没有找到该数据，请重新输入！");
                } else {
                    String update[][] = rc.selectId(textField1.getText());
                    textField4.setText(update[0][0]);
                    textField5.setText(update[0][1]);
                    textField6.setText(update[0][3]);
                    textField2.setText(update[0][4]);
                    comboBox2.setSelectedItem(update[0][2]);
                    if (radioButton2.getText().equals(update[0][5])) {
                        radioButton2.setSelected(true);
                    } else {
                        radioButton2.setSelected(false);
                    }
                    if (radioButton3.getText().equals(update[0][5])) {
                        radioButton3.setSelected(true);
                    } else {
                        radioButton3.setSelected(false);
                    }
                    comboBox3.setSelectedItem(update[0][6]);
                    textField7.setText(update[0][7]);
                }
            } else {
                RoomContorller rc = new RoomContorller();
                if (rc.selectName(textField1.getText()).length == 0) {
                    JOptionPane.showMessageDialog(null, "没有找到该数据，请重新输入！");
                } else {
                    String update[][] = rc.selectName(textField1.getText());
                    textField4.setText(update[0][0]);
                    textField5.setText(update[0][1]);
                    textField6.setText(update[0][3]);
                    textField2.setText(update[0][4]);
                    comboBox2.setSelectedItem(update[0][2]);
                    if (radioButton2.getText().equals(update[0][5])) {
                        radioButton2.setSelected(true);
                    } else {
                        radioButton2.setSelected(false);
                    }
                    if (radioButton3.getText().equals(update[0][5])) {
                        radioButton3.setSelected(true);
                    } else {
                        radioButton3.setSelected(false);
                    }
                    comboBox3.setSelectedItem(update[0][6]);
                    textField7.setText(update[0][7]);
                }
            }
        }
    }

    private class deleteRoom extends AbstractAction {
        private deleteRoom() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action4.Name_3"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            RoomContorller rc=new RoomContorller();
            int flag=rc.deleteRoom(textField4.getText());
            if(flag==-1){
                JOptionPane.showMessageDialog(null,"该系统无此数据，无需再删除");
            }else if(flag==1){
                JOptionPane.showMessageDialog(null,"删除成功！");
                dispose();
                new Index().setVisible(true);
            }if(flag==0){
                JOptionPane.showMessageDialog(null,"删除失败！");
            }
        }
    }
}
